<!--
 * @Description: 
 * @Author: 胡涛
 * @Date: 2023-09-13 21:16:35
 * @LastEditors: 胡涛
 * @LastEditTime: 2023-11-22 21:59:08
-->
<template>
  <a-select
    :options="options"
    :value="value"
    @change="onValueChanged"
    v-bind="$props"
    placeholder="请选择企业信息"
    show-search
    :filter-option="filterOption"
  >
  </a-select>
</template>

<script lang="ts" setup>
import { computed } from "vue";
import { useDataStore } from "@/store";
import { storeToRefs } from "pinia";

const emits = defineEmits(["update:value", "update:name", "change"]);

const props = defineProps({
  value: { type: [String] },
  name: { type: [String] },
  mode: { type: String, default: "" },
});

const { enterpriseItems } = storeToRefs(useDataStore());

const options = computed(() => {
  return enterpriseItems.value.map((x) => {
    return { label: x.name, value: x.id };
  });
});

const filterOption = (input: string, option: any) => {
  return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};

const onValueChanged = (value: string) => {
  let item = enterpriseItems.value.find((x) => x.id == value);
  emits("change", item);
  emits("update:value", value);
  emits("update:name", item?.name);
};
</script>

<style lang="less" scoped></style>
